package com.shanzhu.beadhouse.controller;


import cn.hutool.json.JSONUtil;
import com.shanzhu.beadhouse.common.constant.Constant;
import com.shanzhu.beadhouse.entity.base.Result;
import com.shanzhu.beadhouse.entity.query.*;
import com.shanzhu.beadhouse.service.IServicePurchaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "服务项目")
@RestController
@RequestMapping("/service/purse")
@PreAuthorize("@AuthorityAssert.hasAuthority('/health/servicecare') or @AuthorityAssert.hasAuthority('/health/serveLogForNurse')")
public class ServicePurchaseController {
    @Resource
    private IServicePurchaseService servicePurchaseService;

    @PostMapping("/addPurchase")
    @ApiOperation(value = "批量新增项目购买记录", notes = Constant.DEVELOPER+Constant.EMPEROR_WEN)
    public Result addPurchase(@ApiParam(value = "批量新增项目购买记录列表请求实体")@RequestBody AddPurchaseFromListQuery query,
                              @ApiParam(value = "接口访问请求头",required = true)@RequestHeader String token){
        return servicePurchaseService.addPurchase(query);
    }

    @GetMapping("/pagePurchaseByKeys")
    @ApiOperation(value = "分页获取服务项目购买记录", notes = Constant.DEVELOPER+Constant.EMPEROR_WEN)
    public Result pagePurchaseByKeys(@ApiParam(value = "分页获取服务项目购买记录列表请求实体")  PagePurchaseByKeysQuery query,
                              @ApiParam(value = "接口访问请求头",required = true)@RequestHeader String token){
        return servicePurchaseService.pagePurchaseByKeys(query);
    }

    @GetMapping("/deletePurchaseByKeys")
    @ApiOperation(value = "删除项目购买记录", notes = Constant.DEVELOPER+Constant.EMPEROR_WEN)
    public Result deletePurchaseByKeys(@ApiParam(value = "删除服务请求实体", required = true) DeletePurchaseQuery query,
                                   @ApiParam(value = "接口访问请求头", required = true) @RequestHeader String token){
        System.out.println(JSONUtil.toJsonStr(query));

        return servicePurchaseService.deletePurchase(query);
    }


    @GetMapping("/getPurchaseById")
    @ApiOperation(value = "获取项目购买记录", notes = Constant.DEVELOPER+Constant.EMPEROR_WEN)
    public Result getPurchase(@ApiParam(value = "获取项目购买记录请求实体", required = true) GetPurchaseByIdQuery query,
                                       @ApiParam(value = "接口访问请求头", required = true) @RequestHeader String token){
        System.out.println(JSONUtil.toJsonStr(query));

        return servicePurchaseService.getPurchase(query);
    }

    @GetMapping("/resetHoldById")
    @ApiOperation(value = "追加购买", notes = Constant.DEVELOPER+Constant.EMPEROR_WEN)
    public Result resetHoldById(@ApiParam(value = "追加购买请求实体", required = true) ResetHoldQuery query,
                              @ApiParam(value = "接口访问请求头", required = true) @RequestHeader String token){
        System.out.println(JSONUtil.toJsonStr(query));

        return servicePurchaseService.resetHoldById(query);
    }

}
